﻿#ifndef QTTOOLS_H
#define QTTOOLS_H

#include <QObject>

#define KB_SIZE  (1024)
#define MB_SIZE  (KB_SIZE * 1024)
#define GB_SIZE  (MB_SIZE * 1024)

#ifdef QtUi
#include <QtUi>
class QTUI_EXPORT QtTools {
#else
class QtTools {
#endif
public:
    static void getVersion(QString *_ver, QString *_date, QString *_time);
    static void msSleep(int _msc);
    static void checkDir(const QString &_dir);
    static void checkDirs(QStringList _dirs);
    static void initAppPath();
    static void clearDir(const QString &_path);

    static QString fileSize(qint64 size);
    static QDate buildDate(QString _date);

    static bool isBigEndian();

    static QByteArray baFromFloatBigEndian(float _f);

    static QByteArray baFromUint32BigEndian(const quint32 _ustate);

    static QByteArray baFromUint16BigEndian(const quint16 _id);

    static float floatFromByteArray(QByteArray arr);

    static quint32 uint32FromByteArray(QByteArray arr);
    static quint64 uint64FromByteArray(QByteArray arr);
    static qint16 int16FromByteArray(QByteArray arr);

    static float floatFromHL(quint16 hvalue, quint16 lvalue);

    static quint16 MODBUS_CRC16(quint8 *pushdata, quint8 length);
    static quint16 GetCrcData(const QByteArray &data);
    static QByteArray GetCRCData(const QByteArray &data);

    static QString Size(qint64 bytes);
    static QString Speed(double speed);
    static QString TimeFormat(int seconds);

    static QString GetDevinfoText(QString type);
    static QByteArray HexStrToByteArray(QString str);
    static char ConvertHexChar(char ch);
    static bool IsIpAddr(const QString &strIp);

public:
    static QString m_strAppPath;
    static QString m_strConfPath;
    static QString m_strIconsPath;
    static QString m_strWallpaperPath;
    static QString m_strDesktopFilePath;
};

#endif // QTTOOLS_H
